<template>
  <div class="factory-container">
    <div class="factory-main">
      <!-- 左侧tab -->
      <left-tab @tabClick="tabClick" />

      <!--  <span style="background: red" @click="get">获取全量位置信息</span>
      <span style="background: hotpink" @click="saveUpdate">修改并保存位置信息</span> -->

      <!-- 右侧单位信息 -->
      <FactoryDetail v-if="tabIndex === 0" :qy-info="qyInfo" :qy-contact-info="qyContactInfo" />

      <!-- 右侧附件信息 -->
      <Attachment v-if="tabIndex === 1" :qy-info="qyInfo" />
    </div>
    <!-- 编辑单位信息弹层 -->
    <EditfactoryInfo
      v-if="showEditFactory"
      :qy-contact-info="qyContactInfo"
      :qy-info="qyInfo"
      @uploadData="uploadData"
    />
  </div>
</template>

<script setup lang="ts">
import LeftTab from './leftTab/index.vue'
import FactoryDetail from './FactoryDetail/index.vue'
import Attachment from './attachment/index.vue'
import EditfactoryInfo from './EditFactory/EditfactoryInfo.vue'
import { queryQyxxInfo, queryContactInfo } from '@/service/api'
import { emitter } from '@/composables'
const chemicalStore = useChemicalStore()
const showEditFactory = ref(false)
provide('showEditFactory', showEditFactory)

const tabIndex = ref(0)
const tabClick = (id: any) => {
  tabIndex.value = id
}

const qyInfo = ref([])
const qyContactInfo = ref([
  {
    id: 0,
    ryzw: '法人',
    // rymc: '未采集',
    // ryyddh: '未采集',
    // ryzbdh: '未采集',
  },

  {
    id: 1,
    ryzw: '企业负责人',
    // rymc: '未采集',
    // ryyddh: '未采集',
    // ryzbdh: '未采集',
  },
  {
    id: 2,
    ryzw: '安全负责人',
    // rymc: '未采集',
    // ryyddh: '未采集',
    // ryzbdh: '未采集',
  },
  {
    id: 3,
    ryzw: '生产调度责任人',
    // rymc: '未采集',
    // ryyddh: '未采集',
    // ryzbdh: '未采集',
  },
  {
    id: 4,
    ryzw: '消防安全管理人',
    // rymc: '未采集',
    // ryyddh: '未采集',
    // ryzbdh: '未采集',
  },
  {
    id: 5,
    ryzw: '消防安全责任人',
    // rymc: '未采集',
    // ryyddh: '未采集',
    // ryzbdh: '未采集',
  },
])
// function uploadHandler() {
//   getFactoryInfo()
// }
emitter.on('uploadHandler', () => {
  getFactoryInfo()
})
// 获取企业数据
function getFactoryInfo() {
  const params = {
    key: chemicalStore.qyInfo.id,
    ssid: chemicalStore.qyInfo.id,
  }
  queryQyxxInfo(params).then((res: any) => {
    qyInfo.value = res
  })
  queryContactInfo(params).then((res: any) => {
    // res[0].ryzw = '法人'
    // res[1].ryzw = '厂区负责人'
    // res[2].ryzw = '总安全负责人'
    // res[3].ryzw = '总生产调度责任人'
    // res[4].ryzw = '消防安全管理人'
    // res[5].ryzw = '消防安全责任人'
    qyContactInfo.value = res
    // qyContactInfo.value = res.splice(0,10)
  })
}

getFactoryInfo()

onUnmounted(() => {
  emitter.off('uploadHandler')
})
</script>

<style lang="less">
.factory-container {
  width: 100%;
  height: 100%;
  .factory-main {
    position: absolute;
    top: 112px;
    right: 10px;
    display: flex;
    height: calc(100% - 122px);
    z-index: 10;
  }
}
</style>
